<?php
class model_history extends CI_Model {

	public function __construct()
	{
	//ini_set('memory_limit', '-1');
		$this->load->library('fclass');
		$this->load->database();
	}
	public function select($data)
	{		
		//echo $this->fclass->test();
		$this->db->select('*');
		$this->db->from('tbl_sale_historys');
		$this->db->join('tbl_customers', 'tbl_customers.cust_id = tbl_sale_historys.cust_id');
		$this->db->join('tblusers', 'tblusers.uId = tbl_sale_historys.user_id');

		if(count($data["array_uId"])>1)
			$this->db->or_where_in('cust_creator_id', $data["array_uId"]); 

		if(isset($data["comp_type"])&&$data["comp_type"]!="")
			$this->db->where('comp_type',$data["comp_type"]);

		if(isset($data["user_id"])&&$data["user_id"]!="")
			$this->db->where('tbl_sale_historys.user_id',$data["user_id"]);
		
		if(isset($data["where"])&&$data["where"]!="")
			$this->db->where("(cust_first_name LIKE '%".$this->fclass->cleanup_text($data["where"])."%' OR  cust_last_name LIKE '%".$this->fclass->cleanup_text($data["where"])."%' OR his_action LIKE '%".$this->fclass->cleanup_text($data["where"])."%')");

		if(isset($data["order_by"])&&$data["order_by"]!="")
			$this->db->order_by($data["order_by"]); 

		if(isset($data["limit"])&&$data["limit"]!="")
			$this->db->limit($data["limit"], $data["paging"]);

		$query = $this->db->get();
		//echo $this->db->last_query();
		//print_r($query);
		return $query->result_array();		
	}


	public function insert($data)
	{
		$this->db->trans_start();
		$this->db->insert('tbl_sale_historys', $data); 
		$insert_id = $this->db->insert_id();
   		$this->db->trans_complete();
   		return $insert_id;
		
	}




	

	

}
	
?>